/*
 * @lc app=leetcode.cn id=121 lang=javascript
 *
 * [121] 买卖股票的最佳时机
 */

// @lc code=start
/**
 * @param {number[]} prices
 * @return {number}
 */
var maxProfit = function(prices) {
    let slow = prices[0]
    let fast = prices[0]
    let profit = 0
    for (let index = 1; index < prices.length; index++) {
        fast = prices[index]
        if (fast - slow < 0) {
            slow = fast
        }
        profit = Math.max(profit, fast - slow)
    }
    return profit
};
// @lc code=end

